home *** CD-ROM | disk | FTP | other *** search
- Path: news.eclipse.net!usenet
- From: steve@eclipse.net (Steve Teale)
- Newsgroups: comp.lang.c++
- Subject: Re: A simple question for all the C++ gurus out there!
- Date: Wed, 14 Feb 1996 02:23:10 GMT
- Message-ID: <4frh58$pbk@lunar.eclipse.net>
- References: <3120F95F.659@iglou.com>
- NNTP-Posting-Host: ne_37.eclipse.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- "Abe L. Getchell" <panther@iglou.com> wrote:
-
- >I am trying to write a public member function that will use a private
- >data member from which it inherited from the base class. This won't compile.
- >It gives me an error message like "A::a private data member not accessible in
- >class B". Why won't this work if the prvate data member being inherited from
- >the base class A be a private data member of the derived class?
-
- >Abe L. Getchell
-
- >Please respond via E-Mail if possible...
-
- That's just part of what private means.
-
- If you want members of the base class to be generally private, but
- available to derived classes, use protected.
-
- class A {
- ...
- private:
- int a;
- };
-
- class B : public A {
- public:
- void foo();
- private:
- ....
- };
-
- void B::foo()
- {
- a++; // error - a is not accessible
- }
-
- Use instead
-
- class A {
- ...
- protected:
- int a;
- };
-
-